#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 5, M = 1e4 + 5;
/*
fleft [i][j]表示遇到第i个西瓜朝向为左、消耗j点体力值所得的最多水果数
fright[i][j]表示遇到第i个西瓜朝向为右、消耗j点体力值所得的最大水果数
 */
int fleft[N][M], fright[N][M];

int main() {

  int n, m;
  cin >> n >> m;
  string s;
  cin >> s;
  s = '0' + s;
  memset(fright, 0xaf, sizeof(fright)); // 初始化很小,是个负值
  memset(fleft, 0xaf, sizeof(fleft));
  fright[0][0] = 0;              // 初始值：fr[0][0]=0 初始人朝右
  for (int i = 1; i <= n; i++) { // 遇到第i个西瓜
    int x;
    x = s[i] - '0';
    for (int j = 0; j <= m; j++) { // 已消耗体力值
      // 不动
      fright[i][j] = max(fright[i][j], fright[i - 1][j]),
      fleft[i][j] = max(fleft[i][j], fleft[i - 1][j]);
      // 原地上切
      if (j >= 3) {
        fright[i][j] = max(fright[i][j], fright[i - 1][j - 3] + (x == 1));
        fleft[i][j] = max(fleft[i][j], fleft[i - 1][j - 3] + (x == 3));
      }
      // 原地下切
      if (j >= 2) {
        fright[i][j] = max(fright[i][j], fright[i - 1][j - 2] + (x == 2));
        fleft[i][j] = max(fleft[i][j], fleft[i - 1][j - 2] + (x == 4));
      }
      // 转向
      if (j >= 6) {
        fright[i][j] = max(fright[i][j], fleft[i - 1][j - 6]);
        fleft[i][j] = max(fleft[i][j], fright[i - 1][j - 6]);
      }
      // 转向上切
      if (j >= 9) {
        fright[i][j] = max(fright[i][j], fleft[i - 1][j - 9] + (x == 1));
        fleft[i][j] = max(fleft[i][j], fright[i - 1][j - 9] + (x == 3));
      }
      // 转向下切
      if (j >= 8) {
        fright[i][j] = max(fright[i][j], fleft[i - 1][j - 8] + (x == 2));
        fleft[i][j] = max(fleft[i][j], fright[i - 1][j - 8] + (x == 4));
      }
    }
  }
  int ans = 0;
  for (int j = 1; j <= m; j++)
    ans = max(ans, max(fright[n][j], fleft[n][j]));
  cout << ans;
  return 0;
}